package com.example.demo.leetcode100题;

import com.example.demo.StopWatchTemplate;
import java.util.Arrays;

/**
 * @author：zzc
 * @date: 2022/9/4
 */
public class 排序之冒泡 {

    public static void main(String[] args) {

        System.out.println(StopWatchTemplate.doSupplier(() -> bubbleSort(new int[]{1, 2, 4, 5, 6, 3, 2, 4, 6, 2, 6, 7, 78, 4, 5, 45, 2, 3, 42, 4, 1, 24, 2, 6, 4, 57, 45, 2345})));
    }

    private static String bubbleSort(int[] ints) {
        if (ints.length == 0) {
            return null;
        }

        for (int i = 0; i < ints.length; i++) {
            for (int j = 0; j < ints.length - i - 1; j++) {
                if (ints[j] > ints[j + 1]) {
                    int temp = ints[j];
                    ints[j] = ints[j + 1];
                    ints[j + 1] = temp;
                }
            }
        }
        return Arrays.toString(ints);
    }

}
